import 'dart:io';

import 'package:dbio_utils/fasta/indexed_fasta.dart';
import 'package:dbio_utils/generic_filehandle/local_file.dart';
import 'package:dbio_utils/gff/gff.dart';
import 'package:dbio_utils/gff/util.dart' as util;

import 'package:flutter_test/flutter_test.dart';

import 'package:dbio_utils/dbio_utils.dart';

void main() {
  test('adds one to input values', () {
    final calculator = Calculator();
    expect(calculator.addOne(2), 3);
    expect(calculator.addOne(-7), -6);
    expect(calculator.addOne(0), 1);
    expect(() => calculator.addOne(null), throwsNoSuchMethodError);
  });

  test('GFF3 utils', () async {
    expect(util.escape('5'), '5');

    print(util.parseDirective('##sequence-region no_start_end_on_sequence_region'));

    expect(util.unescape(' '), ' ');
    expect(util.unescape('5'), '5');

    [
      [
        'foo=bar',
        {
          'foo': ['bar']
        }
      ],
      [
        'ID=Beep%2Cbonk%3B+Foo\n',
        {
          'ID': ['Beep,bonk;+Foo']
        }
      ],
      [
        'Target=Motif;rnd-family-27\n',
        {
          'Target': ['Motif']
        }
      ],
    ].forEach((List arr) {
      expect(util.parseAttributes(arr[0]), arr[1]);
    });

    List tests = [
      [
        'FooSeq\tbarsource\tmatch\t234\t234\t0\t+\t.\tID=Beep%2Cbonk%3B+Foo\n',
        {
          'attributes': {
            'ID': ['Beep,bonk;+Foo'],
          },
          'end': 234,
          'phase': null,
          'score': 0,
          'seq_id': 'FooSeq',
          'source': 'barsource',
          'start': 234,
          'strand': '+',
          'type': 'match',
        },
      ],
      [
        '${util.escapeColumn(
          'Noggin,+-%Foo\tbar',
        )}\tbarsource\tmatch\t234\t234\t0\t+\t.\t.\n',
        {
          'attributes': {},
          'end': 234,
          'phase': null,
          'score': 0,
          'seq_id': 'Noggin,+-%Foo\tbar',
          'source': 'barsource',
          'start': 234,
          'strand': '+',
          'type': 'match',
        },
      ],
    ];
    tests.forEach((arr) {
      var input = arr[0], output = arr[1];
      expect(util.parseFeature(input).json, output);
      expect(util.formatFeature(GffFeature(output)), input);
      //expect(util.formatFeature(util.parseFeature(input)), input);
      expect(util.parseFeature(util.formatFeature(GffFeature(output))).json, output);
    });
  });
}
